<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Object</title>
</head>
<body>
    <script>
        var Comm = Comm || {};
        (function(Comm) {
            let Person = function(name, age) {
                this._name = name;
                this._age = age;
            }
            Person.prototype.info = function() {
                let self = this;
                return `NAME=${this._name}, AGE=${this._age}`;
            }
            
            let Student = function(name, age, id) {
                Person.call(this, name, age);
                this._id = id;
                this.arr = [];
            }
            Student.prototype = new Person();
            Student.prototype.constructor = Student;
            Student.superClass = Person.prototype;
            Student.prototype.getStuId = function() {
                return this._id;
            }

            
            
            let Teacher = function(name, age, id) {
                Person.call(this, name, age);
                this._tid = id;
                this.arr = [];
            }
            Teacher.prototype = Object.create(Person.prototype);
            Teacher.prototype.constructor = Teacher;
            Teacher.superClass = Person.prototype;
            Teacher.prototype.getTeacherId = function() {
                return this._tid;
            }

            Comm.Teacher = Teacher;
            Comm.Student = Student;
        })(Comm);
        let Stu = Comm.Student;
        let stu1 = new Stu('Jack', 26, 1);
        let stu2 = new Stu('Rose', 25, 2);
        console.log('stu1.__proto__ === stu2.__proto__ => ', stu1.__proto__ === stu2.__proto__);
        console.log('stu1.info = ', stu1.info());
        console.log('stu2.info = ', stu2.info());
        console.log('stu1.getStuId = ', stu1.getStuId());
        console.log('stu2.getStuId = ', stu2.getStuId());
        stu1.arr.push(1, 2, 3);
        console.log('Before, stu1 = ', stu1.arr.join(','));
        stu2.arr.push(4, 5, 6);
        console.log('After, stu1 = ', stu1.arr.join(','));
        console.log('After, stu2 = ', stu2.arr.join(','));
        stu1.__proto__.tt = 100;
        console.log('Stu.prototype = ', Stu.prototype);
        console.log('Before change, stu1.tt = ', stu1.tt);
        console.log('Before change, stu2.tt = ', stu2.tt);
        stu1.__proto__.tt = 200;
        console.log('After change, stu1.tt = ', stu1.tt);
        console.log('After change, stu2.tt = ', stu2.tt);


        let T = Comm.Teacher;
        let t1 = new T('Jack', 26, 1);
        let t2 = new T('Rose', 25, 2);
        console.log('t1.info = ', t1.info());
        console.log('t2.info = ', t2.info());
        console.log('t1.getTeacherId = ', t1.getTeacherId());
        console.log('t2.getTeacherId = ', t2.getTeacherId());
        t1.arr.push(1, 2, 3);
        console.log('Before, t1 = ', t1.arr.join(','));
        t2.arr.push(4, 5, 6);
        console.log('After, t1 = ', t1.arr.join(','));
        console.log('After, t2 = ', t2.arr.join(','));
        t1.__proto__.tt = 100;
        console.log('T.prototype = ', T.prototype);
        console.log('Before change, t1.tt = ', t1.tt);
        console.log('Before change, t2.tt = ', t2.tt);
        t1.__proto__.tt = 300;
        console.log('After change, t1.tt = ', t1.tt);
        console.log('After change, t2.tt = ', t2.tt);
        console.log('After change, stu1.tt = ', stu1.tt);
        console.log('After change, stu2.tt = ', stu2.tt);

        
        console.log('t1.__proto__ === stu2.__proto__ => ', t1.__proto__ === stu2.__proto__);
    </script>
</body>
</html>